(* record *)

(* creation du nouveau type *)
type vector = 
{
		max : int;
	mutable	size : int;
		tab : (int*int*int) array;	
}


let init_vect n init = 
{
	size = 0;
        max = n;
        tab = Array.make n init
}


let is_full vect =
	vect.max = vect.size


let is_empty vect =
	vect.size = 0

let add_last elem = function
	| v when is_full v 	-> failwith "vector is full"
	| v 			-> v.tab.(v.size) <- elem;
				v.size <- v.size + 1


let add_first elem = function
	| v when is_full v	-> failwith "vector is full"
	| v 			-> for i = v.size + 1 downto 1 do
					v.tab.(i+1) <- v.tab.(i);
				done;
				v.tab.(0) <- elem;
				v.size <- v.size + 1


let get_elem index = function
	| v when is_empty v	-> failwith "vector is empty"
	| v			-> v.tab.(index)


let iter func v =
	for i = 0 to v.size do
		func v.tab.(i);
	done
	
let map func v =
	let newV = init_vect v.max (func v.tab.(0))  in 
		for i = 1 to v.size do
			add_last (func v.tab.(i)) newV
		done;
		newV


let inplace_map func v =
	for i = 0 to v.size do
		v.tab.(i) <- func v.tab.(i)
	done

